import axios from 'axios';

const $ajax = {
    install: function (Vue) {
        let methods = ['get', 'put', 'post', 'delete', 'fetch'];
        Vue.prototype.$axios = axios;
        methods.forEach(method => {
            Vue.prototype['$' + method] = (url, data, config) => {
                return new Promise((resolve, reject) => {
                    axios[method](url, data, config).then(res => {
                        if (res.status === 200) {
                            resolve(res.data)
                        } else {
                            reject(result);
                        }
                    }).catch(error => {
                        reject(error);
                    })
                })
            } 
        })
    }
}
export default $ajax;